package com.example.pei.ithinklearnt.view.customview;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;

import com.example.pei.ithinklearnt.R;


/**
 * 这个对话框用来给动态的，删除 。复制。屏蔽等
 * Created by Pei on 2017/11/24.
 */

public class dynamicSelectedDialog extends Dialog implements View.OnClickListener{

    private Context mContext;
    private Button button_shield;
    private Button button_copy;
    private Button button_delete;
    private Listener mListener;

    private int  permission;   // 0 代表可以有删除button,管理员或者是自己

    public interface Listener{
        void onClick(View v);
    }

    public dynamicSelectedDialog(@NonNull Context context) {
        super(context);
        this.mContext=context;
    }

    public dynamicSelectedDialog(@NonNull Context context, int themeResId,int  permission,Listener listener) {
        super(context, themeResId);
        this.mContext=context;
        this.mListener=listener;
        this.permission=permission;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.dynamic_selected_dialog);

        button_shield=(Button)findViewById(R.id.btn_shield);
        button_copy=(Button)findViewById(R.id.btn_copy);
        button_delete=(Button)findViewById(R.id.btn_del);

        button_shield.setOnClickListener(this);
        button_copy.setOnClickListener(this);
        button_delete.setOnClickListener(this);

        if(permission==0){//不是自己发送的，且不是管理员
            //删除按键不可见
            findViewById(R.id.tv_line2).setVisibility(View.GONE);
            button_delete.setVisibility(View.GONE);
            //屏蔽可见
            button_shield.setVisibility(View.VISIBLE);
            findViewById(R.id.tv_line1).setVisibility(View.VISIBLE);
            //最下方的复制重新设置样式
            button_copy.setBackgroundResource(R.drawable.button_bottom_selector);

        }else if(permission==1||permission==2){////是自己发送的，管理员,普通用户无所谓
            //删除按键可见
            findViewById(R.id.tv_line2).setVisibility(View.VISIBLE);
            button_delete.setVisibility(View.VISIBLE);
            //屏蔽按键不可见
            button_shield.setVisibility(View.GONE);
            findViewById(R.id.tv_line1).setVisibility(View.GONE);

        }else if(permission==3){//不是自己发送的，是管理员
            //删除按键可见
            findViewById(R.id.tv_line2).setVisibility(View.VISIBLE);
            button_delete.setVisibility(View.VISIBLE);
            button_delete.setText("    删除  (管理员身份，谨慎操作!)");
            //屏蔽按键不可见
            button_shield.setVisibility(View.GONE);
            findViewById(R.id.tv_line1).setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View view) {
        mListener.onClick(view);
    }
}
